<?php 
require_once("konf.php");
$kask=$yhendus->prepare(
    "SELECT nimi, telefon, mail, isikukood, broneering.klient_id
	FROM klient, broneering 
	WHERE klient.klient_id=broneering.klient_id AND broneering.broneering_id=?");
echo $yhendus->error;
  $kask->bind_result($nimi, $telefon, $mail, $isikukood, $klient_id);
  $kask->bind_param("i", $_REQUEST["broneering_id"]);
  $kask->execute();
?>
<?php
 session_start();
 if(!isSet($_SESSION["kasutajanimi"])){
 header("Location: login.php");
 exit();
 }
 date_default_timezone_set('Europe/Helsinki');
?>

<!doctype html>
<html>
<head>
	<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
	
	<title>Broneeringu arveleht</title>
	<link rel='stylesheet' type='text/css' href='style.css' />
	<link rel='stylesheet' type='text/css' href='print.css' media="print" />

</head>
  <body>
  
  <a href="admin.php">TAGASI</a>

	<div id="page-wrap">

		<textarea id="header">ARVE</textarea>
		
		<div id="identity">

            <a>
<?php
	if(!isSet($_SESSION["loendur"])){
		$_SESSION["loendur"]=0;
		}
	$_SESSION["loendur"]++;

	if($kask->fetch()){
	$date=date("Y/m/d");
	echo "
		<a>Nimi: $nimi</a></br>
		<a>Telefon: $telefon</a></br>
		<a>E-post: $mail</a></br>
		<a>Isikukood: $isikukood</a></br>	
		

	
		</div>
		
		<div style='clear:both'></div>
		
		<div id='customer'>
		</br>

            <a id='customer-title'>IFI Grand Hotel</a>

            <table id='meta'>

		     <tr>
			   <td class='meta-head'>ARVE</td>
			   <td>00$_SESSION[loendur]</td>
			 </tr>

         <tr>

             <td class='meta-head'>Kuupäev</td>
             <td id='date'>$date</td>
         </tr>
		 ";
		}
     $kask->close();
	   
?>

            </table>
		
		</div>
		
		<table id="items">
		
		  <tr>
		      <th>Tüüp</th>
		      <th>Kirjeldus</th>
		      <th>Ühiku hind</th>
		      <th>Tk</th>
		      <th>Kokku</th>
		  </tr>
<?php
	$kask=$yhendus->prepare(
    "SELECT broneering.broneering_id, liik, hind, broneering.algusaeg, broneering.lopuaeg
	FROM broneering ,ruumiliigid, elamine, hinnad
	WHERE elamine.ruumiliigid_id=ruumiliigid.ruumiliigid_id AND hinnad.hinnad_id=ruumiliigid.hinnad_id AND broneering.broneering_id=elamine.broneering_id AND broneering.broneering_id=?");
echo $yhendus->error;
  $kask->bind_result($broneering_id, $liik, $hind, $algusaeg, $lopuaeg);
  $kask->bind_param("i", $_REQUEST["broneering_id"]);
  $kask->execute();

	if($kask->fetch()){
	$start=strtotime($algusaeg);
	$end=strtotime($lopuaeg);
	$datediff = ceil(abs($end - $start) / 86400);
	$hindkokku=($hind*$datediff);
	echo $yhendus->error;
	echo "
		<tr class='item-row'>
		<td class='item-name'>Majutus</td>
		<td class='description'>$liik</td>
		<td class='cost'>$hind €</td>
		<td class='qty'>$datediff</td>
		<td class='cost'>$hindkokku €</td>
		</tr>

		  <tr id='hiderow'>
		    <td colspan='5'></td>
		  </tr>
		  
		  <tr>

		      <td colspan='2' class='blank'> </td>
		      <td colspan='2' class='total-line'>KOKKU</td>
		      <td class='total-value'><div id='total'>$hindkokku €</div></td>
		  </tr>
		  <tr>
		      <td colspan='2' class='blank'> </td>
		      <td colspan='2' class='total-line'>Makstud</td>

		      <td class='total-value'><textarea id='paid'>0.00 €</textarea></td>
		  </tr>
		
		</table>
				   ";
		}
	     $kask->close();
	   
?>
		
		<div id="terms">
		  <a> IFI Grand Hotel, Narva mnt. 25, Tallinn</a>
		</div>

	</div>
	
</body>

	

  
</html>

